package Algorithms.chapter3.ch1;

public class SeparateChainingHashST<Key,Value> {
    private int N;//键值对对数
    private int M;//散列表大小
    private SequentialSearchST<Key,Value>[] st;//存放链表对象的数组

    public SeparateChainingHashST(){
        this(997);
    }
    public SeparateChainingHashST(int M){
        //创建M条链表
        this.M = M;
        st = (SequentialSearchST<Key,Value>[]) new SequentialSearchST[M];
        for (int i = 0; i < M ; i++) {
            st[i] = new SequentialSearchST();
        }
    }
    private int hash(Key key){
        //使用散列函数后删去符号位置，返回hash值
        return (key.hashCode()&0x7fffffff)%M;
    }
    public Value get(Key key){
        //先找到一个链表，再从链表中去寻找
        return (Value) st[hash(key)].get(key);
    }
    public void put(Key key,Value val){
        st[hash(key)].put(key,val);
    }
    




}
